import { PORT1 } from '@/api/config/servicePort';
import http from '@/api';
import { UserInterface } from '@/api/interface/auth/user';
import { PublicParams } from '@/api/interface/publicParams';
import { RoleInterface } from '@/api/interface/auth/role';
/**
 * @name 用户管理模块
 */

// 用户登录
export const loginApi = (params: UserInterface.ReqLogin) => {
  return http.post<UserInterface.ResToken>(PORT1 + `/user/v1/login`, params, { loading: false, formParams: true });
};

// 获取用户权限
export const getAuthBySysUser = () => {
  return http.get<RoleInterface.AuthByUser>(PORT1 + `/user/v1/getAuthByUser`, {}, { loading: false });
};

// 用户退出登录
export const logoutApi = () => {
  return http.post(PORT1 + `/user/v1/logout`);
};

// 删除用户
export const userDeleteById = (params: PublicParams.ReqId) => {
  return http.get<UserInterface.ResToken>(PORT1 + `/user/v1/deleteById`, params);
};

// 用户注册
export const userRegister = (params: PublicParams.ReqId) => {
  return http.post<UserInterface.ResToken>(PORT1 + `/user/v1/register`, params);
};

// 用户查询
export const userPageListUser = (params: PublicParams.ReqId) => {
  return http.post<PublicParams.ResPage<UserInterface.ResUser>>(PORT1 + `/user/v1/pageListUser`, params);
};

// 修改用户状态
export const userUpdateStatus = (params: PublicParams.ReqStatus) => {
  return http.post<PublicParams.ResPage<UserInterface.ResUser>>(PORT1 + `/user/v1/updateStatus`, params);
};

/**
 * 用户修改密码
 */
export const userChangePwd = (params: UserInterface.ReqUserChangePwd) => {
  return http.post(PORT1 + `/user/v1/userChangePwd`, params);
};

/**
 * 管理员修改密码
 */
export const userAdminChangeUserByPwd = (params: UserInterface.ReqAdminChangeUserByPwd) => {
  return http.post(PORT1 + `/user/v1/adminChangeUserByPwd`, params);
};
